/*
 * Copyright (c) 2020-2024 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this list of
 *    conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
 *    of conditions and the following disclaimer in the documentation and/or other materials
 *    provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
 *    to endorse or promote products derived from this software without specific prior written
 *    permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef _BMSINFO_H_
#define _BMSINFO_H_

#include "common.h"

// #include "hw_type.h"
// #include "iota_init.h"
// #include "iota_cfg.h"
// #include "log_util.h"
// #include "json_util.h"
// #include "string_util.h"
// #include "iota_login.h"
// #include "iota_datatrans.h"
// #include "cJSON.h"
// #include "iota_error_type.h"
// #include "mqttv5_util.h"
// #include "securec.h"
// #include "subscribe.h"

#define SIZE_LISTKEY                                    200

#define SOFTWARE_VERSION                                (2024121209U)

#define DELTA_T_THD_DEFAULT                             (300)
#define DELTA_T_WARNING_THD_DEFAULT                     (150)
#define DELTA_VOL_OPEN_THD_DEFAULT                      (300)
#define DELTA_VOL_WARNING_THD_DEFAULT                   (200)
#define CELL_OVER_VOL_THD_DEFAULT                       (4190)
#define CELL_OV_WARNING_THD_DEFAULT                     (4160)
#define CHG_FINISH_CURRENT_THD_DEFAULT                  (120)

#define CELL_UV_OPEN_DEFAULT                            (3100)
#define CELL_UV_WARNING_THD_DEFAULT                     (3150)
/*均衡开启*/
#define V_CELL_DELTA_THD_START                          (5)
/*均衡关闭*/
#define V_CELL_DELTA_THD_STOP                           (3)

#define BALANCE_SWITCH_EN_DEFAULT                       (1)

// 配置项
#define  BATT_Open_POV                          (3771)
#define  BATT_WARN_POV                          (3744)

#define BATT_DSG_PACK_OPEN_UV                   (2790)
#define BATT_DSG_PACK_WARNING_UV                (2835)

/*充电保护一级*/
#define BATT_CHG_OPEN_I                        (550)
#define BATT_CHG_WARNING_I                     (530)

#define BATT_Open_POV                          (3771)
#define BATT_WARN_POV                          (3744)

/*放电参数*/
#define BATT_DSG_OPEN_I                         (550)
#define BATT_DSG_WARNING_I                      (530)

#define CHG_OT_OPEN_THD                         (550)
#define CHG_OT_WARNING_THD_DEFAULT              (500)

#define CELL_OVER_VOL_THD_DEFAULT               (4190)
#define CELL_OV_WARNING_THD_DEFAULT             (4160)
#define CHG_FINISH_CURRENT_THD_DEFAULT          (120)

#define DSG_OT_OPEN_THD                         (600)
#define DSG_OT_WARNING_THD_DEFAULT              (550)

#define DSG_UT_TEMP_THD                         (0)
#define DSG_UT_WARNING_THD_DEFAULT              (100)

#define CHG_UT_TEMP_THD                         (0)
#define CHG_UT_WARNING_THD_DEFAULT              (50)

#define BATT_ALARM3_SOC                         (180)
#define BATT_ALARM2_SOC                         (120)
#define BATT_ALARM1_SOC                         (00)

/*该参数系数是1*/
#define  BATT_RATED_AH                          (140)
/*该参数系数是0.1*/
#define  BATT_RATED_01KWH                       (466)
/*该参数系数是1*/
#define  BIU_SHUNT_TYPE_I_DEFAULT               (100)
/*该参数系数是1*/
#define  BIU_SHUNT_TYPE_V_DEFAULT               (75)

/* 充电需求电流*/
#define  RATE_CHG_CURRENT_THD_DEFAULT           (500)
/* 充电需求电压*/
#define  RATE_CHG_VOL_THD_DEFAULT               (3700)
/* 充电降流单体电压*/
#define  CELL_CHG_THD_DEFAULT                   (4150)

#define ALARM1_ISO_R_DEFAULT                    (50)
#define ALARM2_ISO_R_DEFAULT                    (250)

#define PRECHARGE_RATIO_DEFAULT                 (95)

/*允许接入的控制板数*/
#define MAX_NUMBER_OF_BOARD                             (5)
#define LTC6813_NUM_PER_UINT                            (1)
#define MAX_LTC6813_CHIP_NUM                            (MAX_NUMBER_OF_BOARD * LTC6813_NUM_PER_UINT)
#define LTC6813_CELL_PER_CHIP                           (18)
#define LTC6813_TEMP_PER_CHIP                           (4)
#define VOL_NUM_OF_BOARD                                (LTC6813_CELL_PER_CHIP * LTC6813_NUM_PER_UINT)
#define TEMP_NUM_OF_BOARD                               (LTC6813_TEMP_PER_CHIP * LTC6813_NUM_PER_UINT)
#define MAX__CELL_VOL_NUM                               (MAX_LTC6813_CHIP_NUM * LTC6813_CELL_PER_CHIP)
#define MAX_LL_ERR_CNT_LIMIT                            (10)
#define LL_ERR_CNT_TO_RESET                             (3)

#define AFE_MAX_CHIP_COUNT                              MAX_LTC6813_CHIP_NUM
#define AFE_CELL_NUM_PER_CHIP                           LTC6813_CELL_PER_CHIP
#define AFE_TEMP_NUM_PER_CHIP                           LTC6813_TEMP_PER_CHIP
#define CELL_NUM_PER_UINT                               VOL_NUM_OF_BOARD
#define TEMP_NUM_PER_UINT                               TEMP_NUM_OF_BOARD
#define  BMU_OF_NUM                                     MAX_NUMBER_OF_BOARD
/*每个bms包含的afe个数*/
#define AFE_NUM_PER_BORAD                               LTC6813_NUM_PER_UINT

#define MAX_CEL_VOL_NUM                                 (AFE_MAX_CHIP_COUNT * AFE_CELL_NUM_PER_CHIP)
#define MAX_TEMP_NUM                                    (AFE_MAX_CHIP_COUNT * AFE_TEMP_NUM_PER_CHIP)

#define RT_NAME_RT10K_30TO125
#define CAL_T_OFFSET                                    (80.0f)


#define T_OFFSET                                        (30.0f)
#define MAX_TEMP_VALUE                                  (125.0f)    
#define MIN_TEMP_VALUE                                  (-30.0f)
#define MIN_VALID_TEMP_VALUE                            (MIN_TEMP_VALUE)


#define AFE_SAMPLE_VREF                                 (3000u)
#define VOL_VALID_DEFAULT                               (0X0003FFFF)
#define MIN(a, b)                                       ((a) > (b) ? (b) : (a))
#define MAX(a, b)                                       ((a) > (b) ? (a) : (b))

typedef enum
{
    NORMAL = 0,
    LEVEL1,
    LEVEL2,
    LEVEL3,
} ALARM_T;

typedef struct
{
    uint32_t chg_total_capacity ;           /* 充电容量累计0.1AH */
    uint32_t chg_total_capacity_history;
    uint32_t dsg_total_capacity ;           /* 放电容量累计0.1AH */
    uint32_t dsg_total_capacity_history ;
    uint32_t dsg_total_wh;                  /* 充电电能累计1wH */
    uint32_t dsg_total_wh_history;
    uint32_t chg_total_wh;                  /* 充电电能   1wH */
    uint32_t chg_total_wh_history;
    uint32_t dsg_wh;                        /* 充电电能    */
    uint32_t chg_wh;                        /* 充电电能    */
    uint32_t charge_capacity;               /* 充电容量0.1AH    */
    uint32_t discharge_capacity;            /* 放电容量0.1AH    */
} CAL_T;

typedef enum
{
    MODE_IDLE = 0,                      // 待机模式
    MODE_PRECHARGE,                     // 预充模式
    MODE_PRECHARGE_WAITE,               // 预充电模式
    MODE_DSG,                           // 充电模式
    MODE_CHG,                           // 放电电模式
} work_mode;

typedef struct
{
    uint8_t low_soc;                    /* soc 报警显示=0 无报警 =1 一级报警，=2 二级报警，=3三级报警 */
    uint8_t chg_over_T;                 /* 充电过温 报警显示=0 无报警 =1 一级报警，=2 二级告警 */
    uint8_t dsg_over_T;                 /* 充电过温 报警显示=0 无报警 =1 一级报警，=2 二级告警 */
    uint8_t cell_ov;                    /* 单体过压 报警显示=0 无报警 =1 一级报警，=2 二级告警 */
    uint8_t cell_uv;                    /* 单体压差 报警显示=0 无报警 =1 一级报警，=2 二级告警 */
    uint8_t chg_over_current;           /* 充电过流 报警显示=0 无报警 =1 一级报警，=2 二级告警 */
    uint8_t dsg_over_current;           /* 放电过流 报警显示=0 无报警 =1 一级报警，=2 二级告警 */
    uint8_t pack_ov;                    /* 总压过压 报警显示=0 无报警 =1 一级报警，=2 二级告警 */
    uint8_t pack_uv;                    /* 总压欠压 报警显示=0 无报警 =1 一级报警，=2 二级告警 */
    uint8_t chg_ut;                     /* 充电欠温 报警显示=0 无报警 =1 一级报警，=2 二级告警 */
    uint8_t dsg_ut;                     /* 放电欠温 报警显示=0 无报警 =1 一级报警，=2 二级告警 */
   
    uint8_t delta_t;                    /* 温差过大 报警显示=0 无报警 =1 一级报警，=2 二级告警 */
    uint8_t delta_v;                    /* 压差过大 报警显示=0 无报警 =1 一级报警，=2 二级告警*/
    uint8_t insulation_r;               /* 绝缘电阻 报警显示=0 无报警 =1 一级报警，=2 二级告警 */
    uint8_t balance_t;                  /* 均衡温度 报警显示=0 无报警 =1 一级报警，=2 二级告警 */
    uint8_t balance_err;                /* 均衡故障 报警显示=0 无报警 =1 一级报警，=2 二级告警 */
    uint8_t open_wire;                  /* 断线 报警显示=0 无报警 =1 一级报警，=2 二级告警 */
    uint8_t afe_error;                  /* afe故障 报警显示=0 无报警 =1 一级报警，=2 二级告警 */
    uint8_t chg_com_timeout;            /* 充电通讯超时*/
    uint8_t balance_ot;                 /* 均衡过温*/
    uint8_t precharg_fail;              /* 预充失败*/

    uint8_t T_in_mcu_L2_flag;
    uint8_t T_in_mcu_L1_flag;

    uint8_t dsg_contactor_sticky;       /* 放电接触器粘连 =2 二级告警 */
    uint8_t chg_contactor_sticky;       /* 充电接触器粘连 =2 二级告警 */
    uint8_t heat_contactor_sticky;      /* 加热接触器粘连 =2 二级告警 */
		    
    uint8_t dsg_contactor_delt_v_error;     /* 放电接触器压差大  报警显示=0 无报警 =1 一级报警，=2 二级告警 */
    uint8_t chg_contactor_delt_v_error;     /* 充电接触器压差大  报警显示=0 无报警 =1 一级报警，=2 二级告警 */		
    uint8_t internal_can_com_timeout;       /* 内CAN通讯超时 0： 无报警  1 ：报警，故障可自动清除 */

} _SystemAlarmStru;

typedef struct
{
    uint16_t chgPackVolOpenTHD;         /* 充电总压一级报警阈值*/
    uint16_t chgPackVolWarningTHD;      /* 充电总压 告警降流*/

    uint16_t dsgPackVolOpenTHD;         /* 放电电断开电压*/
    uint16_t dsgPackVolWarningTHD;      /* 放电放电断开告警*/

    int16_t Ip_ChgOpenTHD ;             /* 充电断开电流*/
    int16_t IpChgWarningTHD ;           /* 充电告警值*/

    int16_t Ip_DsgWarningTHD;           /* 放电电断开告警值*/
    int16_t Ip_DsgOpenTHD;              /* 放电电断开电流*/

    int16_t ChgOTOpenTHD;               /* 充电过温开接触器*/
    int16_t ChgOTWarningTHD;            /* 充电过温告警*/
    int16_t DsgOTOpenTHD;               /* 放电过温*/
    int16_t DsgOTWarningTHD;            /* 放电过温告警*/
    int16_t DsgUTOpenTHD;               /* 放电电欠温*/
    int16_t DsgUTWarningTHD;            /* 放电电欠温告警*/

    uint16_t deltaT_OpenTHD;            /* 单体温度1级*/
    uint16_t deltaT_WarningTHD;         /* 单体温度2级*/

    uint16_t deltaVolOpenTHD;           /* 单体压差1级*/
    uint16_t deltaVolWarningTHD;        /* 单体压差2级*/

    uint16_t Tredu_OV_THD;              /* 继电器过温*/
    uint16_t Tredu_UV_THD;              /* 继电器欠温*/

    int16_t T_in_mcu_OV_L1THD;
    int16_t T_in_mcu_OV_L2THD;

    uint16_t SOC_L3THD;                     /* soC 3级报警*/
    uint16_t SOC_L2THD;                     /* soC 2级报警*/
    uint16_t SOC_L1THD;                     /* soC 1级报警*/
    uint16_t origi_SOH;

    uint16_t RatedKWh;                      /* 额定电度*/
    uint16_t Rated_Capacity;                /* 额定容量*/

    uint16_t shunt_I;                       /* 分流器电流值*/
    uint16_t shunt_mV;                      /* 分流器电压值*/

    uint8_t PreductSN[16];
    uint8_t PCBA_SN[16];

    uint8_t PowerOnChnNum;                  /* 供电通道数 主控有效*/
    uint8_t V_FilterRatio;                  /* 电压采集滤波系数*/
    uint8_t T_FilterRatio;                  /* 温度采集滤波系数*/
    int16_t Temp_HeatOff;                   /* 加热关闭温度*/
    int16_t Temp_HeatOn;                    /* 加热开启温度*/
    int16_t chg_ut_l1;                      /* 充电欠温一级*/
    int16_t chg_ut_l2;                      /* 充电欠温二级*/
    uint8_t HiSwitchChnNo;                  /* 高边开关通道数*/
    uint16_t R_hiSwitch;                    /* 高边开关电流检测电阻*/

    uint8_t VdiffStatic_StartBal;           /* 静态单体极差开启门限*/
    uint8_t VdiffStatic_StopBal ;           /* 静态单体极差开启门限*/
    uint16_t iso_r_OpenThd;                 /* 绝缘一级*/
    uint16_t iso_r_WarningThd;              /* 绝缘一级*/

    uint16_t VcellLo_LimitDChgTHD;          /* 单体过低限制放电门限*/
    uint16_t cellOverVolOpenTHD;            /* 单体过压保护门限*/
    uint16_t cellOverVolWaringTHD;          /* 单体过压保护门限*/

    uint16_t cellUnderVolOpenTHD ;          /* 单体欠压压保护门限*/
    uint16_t cellUnderVolWarningTHD ;       /* 单体欠压压保护门限*/

    int16_t Tbalance_OverPretTHD;          /* 均衡过温保护门限*/
    uint16_t Vdiff_PretTHD ;                /* 极差保护门限*/

    uint16_t Vavg_PretTHD;                  /* 平均电压过低保护门限*/
    uint16_t VavgStartBal_High;             /* 平均电压开启均衡上限*/
    uint16_t VavgStartBal_Low ;             /* 平均电压开启均衡下限*/
    uint16_t VcellStartBal_High;            /* 单体电压开启均衡上限*/
    uint16_t VcellStartBal_Low;             /* 单体电压开启均衡下限*/
    uint16_t chg_current_finish_thd;        /* 充电结束电流阈值       */
    uint16_t VdeadStopBal_Low ;             /* 均衡停止死区下限*/
    //uint16_t  Send_DelayTime;             /* 延时时间*/

    uint16_t Rated_chg_current;             /* 额定充电电流        */

    uint16_t Rated_chg_pack_vol;            /* 额定充总压          */
    uint16_t chg_start_dec_curret_of_vol;   /* 单体过高限制充电门限*/

    uint8_t set_eeprom_default;             /* 参数设置EEprom缺省值*/
    uint8_t banlanceSwitch;                 /* 均衡使能开关*/
    int16_t dsg_standby_time;               /* 放电待机时间 */
    uint8_t precharge_ratio;                /* 预充比例，范围最大1-100*/

    uint32_t HwVer;
    uint32_t SwVer;

    uint16_t BatType;
    uint16_t zero_point_current_thd;        /* 低于该值显示电流为0，该值为电流绝对值*/
    int16_t battary_current_off_set;        /* 电池电流偏移值*/
    uint8_t dsg_standby_switch;             /* 放电待机自动关机使能开关 =1 开关使能 */

    uint16_t contactor_close_delta_v;       /* 接触器闭合后，压差大于该值报警阀值 系数0.1*/
    uint16_t contactor_open_delta_v;        /* 接触器粘连压差报警，接触器断开后两端压差小于该值报警系数0.1 */
    uint8_t clear_level1_fault_switch;      /* 清除故障 =1 清除1级故障 */
    uint16_t device_addr;                   /* 外can 地址*/
    uint16_t dsg_limit_current;             /* 放电限制电流*/
    uint16_t dsg_stop_cell_vol;             /* 放电停止单体电压*/
    uint16_t dsg_stop_vol;                  /* 放电停止总压*/
    uint16_t dsg_stop_restart_cell_vol;     /* 放电停止恢复单体电压*/
    uint16_t dsg_stop_restart_vol;          /* 放电停止恢复总压*/
    uint16_t chg_limit_current;             /* 充电限制电流*/
    uint16_t chg_stop_cell_vol;             /* 充电停止单体电压*/
    uint16_t chg_stop_vol;                  /* 充电停止总压*/
    uint16_t chg_stop_restart_cell_vol;     /* 充电停止恢复单体电压*/
    uint16_t chg_stop_restart_vol;          /* 充电停止恢复总压*/
    int16_t fan_on_temp;                   /* 风扇开启温度*/
    int16_t fan_off_temp;                  /* 风扇停止温度*/

} _SystemParamStru;

typedef struct
{
    union
    {
        uint16_t allbits;
        struct
        {
            uint16_t VcellVal : 15;
            uint16_t valid : 1;
        } Bit;
    } Vcell[24];

    union
    {
        uint16_t allbits;
        struct
        {
            uint16_t TcellVal : 15;
            uint16_t valid : 1;
        } Bit;
    } Tcell[14];

} BMU_VOL_TEMP_t;

typedef union
{
    uint16_t allbits;
    struct
    {
        uint8_t bmu_index : 8;
        int8_t bmu_id : 8; /*从控板板号，从0开始*/
    } Bit;
} MAX_MIN_ID_t;

typedef struct
{
    uint16_t Switch1;
    uint16_t Switch2;
    uint16_t Switch3;
    uint16_t Switch4;
    uint16_t Switch5;
    uint16_t Switch6;
}  HI_SWITCH_STATE_T;

typedef  union _OPEN_WIRE_STATE
{
    struct
    {
        uint16_t BT0 : 1;  //线标号
        uint16_t BT1 : 1;
        uint16_t BT2 : 1;
        uint16_t BT3 : 1;
        uint16_t BT4 : 1;
        uint16_t BT5 : 1;
        uint16_t BT6 : 1;
        uint16_t BT7 : 1;
        uint16_t BT8 : 1;
        uint16_t BT9 : 1;
        uint16_t BT10 : 1;
        uint16_t BT11 : 1;
        uint16_t BT12 : 1;
        uint16_t NC : 3;
    } Bit;
    uint16_t ALL;
} OPEN_WIRE_STATE;

typedef union 
{
    struct
    {
        uint32_t bat1 : 1;   
        uint32_t bat2 : 1;
        uint32_t bat3 : 1;
        uint32_t bat4 : 1;
        uint32_t bat5 : 1;
        uint32_t bat6 : 1;
        uint32_t bat7 : 1;
        uint32_t bat8 : 1;
        uint32_t bat9 : 1;
        uint32_t bat10 : 1;
        uint32_t bat11 : 1;
        uint32_t bat12 : 1;
        uint32_t bat13 : 1;   
        uint32_t bat14 : 1;
        uint32_t bat15 : 1;
        uint32_t bat16 : 1;
        uint32_t bat17 : 1;
        uint32_t bat18 : 1;
        uint32_t bat19 : 1;
        uint32_t bat20 : 1;
        uint32_t bat21 : 1;
        uint32_t bat22 : 1;
        uint32_t bat23 : 1;
        uint32_t bat24 : 1;
        uint32_t NC : 8;
    } Bit;
    uint32_t ALL;
} VOL_VALID_t;

typedef union
{
    uint16_t allbits;
    struct
    {
        uint16_t VcellVal;
        uint16_t valid;
    } Bit;
} Vcell_t;

typedef union
{
    uint16_t allbits;
    struct
    {
        float TempVal;
        uint16_t valid;
    } Bit;
} Temp_t;

typedef struct
{
    Vcell_t voltage[VOL_NUM_OF_BOARD];
    int16_t temp[TEMP_NUM_OF_BOARD];                    /*afe读取到的温度数值*/
		    
    uint8_t vol_com_timeout_a[LTC6813_NUM_PER_UINT];    /*每个板的电压AFE的a组通信超时计数*/
    uint8_t vol_com_timeout_b[LTC6813_NUM_PER_UINT];    /*每个板的电压AFE的b组通信超时计数*/
    uint8_t vol_com_timeout_c[LTC6813_NUM_PER_UINT];    /*每个板的电压AFE的c组通信超时计数*/
    uint8_t vol_com_timeout_d[LTC6813_NUM_PER_UINT];    /*每个板的电压AFE的d组通信超时计数*/
    uint8_t vol_com_timeout_e[LTC6813_NUM_PER_UINT];    /*每个板的电压AFE的e组通信超时计数*/
    uint8_t vol_com_timeout_f[LTC6813_NUM_PER_UINT];    /*每个板的电压AFE的f组通信超时计数*/
    uint8_t temp_com_timeout_b[LTC6813_NUM_PER_UINT];   /*每个板的温度AFE的b组通信超时计数*/
    uint8_t temp_com_timeout_c[LTC6813_NUM_PER_UINT];   /*每个板的温度AFE的c组通信超时计数*/
    uint8_t temp_com_timeout_d[LTC6813_NUM_PER_UINT];   /*每个板的温度AFE的d组通信超时计数*/
    uint8_t balance_status[VOL_NUM_OF_BOARD];	        /*每个字节表示一个单体电压均衡*/ 
    float temprature[TEMP_NUM_OF_BOARD];              /*每个板校准后的温度值*/
    Temp_t tempratureCaliVal[TEMP_NUM_OF_BOARD];        /*温度校准值*/
    VOL_VALID_t vol_valid;

} BMU_BOARD_t;

typedef struct
{
    uint16_t battery_total_vol;
    uint16_t battery_total_vol_cell_sum;    /*电池总压=单体电压累加和*/
    uint16_t ch1_vol;
    uint16_t ch2_vol;
    uint16_t ch4_vol;
    uint16_t cc2_vol;                       /*系数0.01*/

    int16_t I_system;
    uint16_t R_iso;

    float SOC;
    uint16_t soc_history;

    uint8_t SOH;
    int16_t Calc_SOC;
    uint16_t Rp_iso;
    uint16_t Rn_iso;

    MAX_MIN_ID_t VcellMaxID;
    MAX_MIN_ID_t VcellMinID;
    MAX_MIN_ID_t Tmax_ID;
    MAX_MIN_ID_t Tmin_ID;
    float Tmax;
    float Tmin;
    float env_temperature;
    float env_humidity;
    uint16_t env_mq2;

    uint16_t VcellMax;
    uint16_t VcellMin;
    uint16_t Vdelta_Cell;
    uint16_t VAvg_Cell;
    float Tcell_avg;
    uint16_t temp_valid_num;                /* 温度有效数量 */
    uint16_t vol_valid_num;                 /* 电压有效数量 */

    uint32_t accumulate_work_time;          /* 工作时间单位s */
    uint32_t work_time_history ;
    uint8_t power_off_key_state;            /* 关机按钮的状态  1 关机 */
    uint16_t full_charge_count;             /* 满充充电次数 系数0.1 */

    uint32_t power_on_time;                 /* 上电开机时间 */
    uint8_t power_off;                      /* 1 表示执行关行关机，0 不关机 */
    int16_t deltaT;
    uint16_t left_time_in_standby;          /* 待机剩余时间 */
    CAL_T cal;
    uint16_t power12V_vol;                  /* power电压 */
    BMU_BOARD_t bmu[BMU_OF_NUM];

    uint8_t ctrl_HSD_cmd ;
    _SystemParamStru SysParamStru;
    _SystemAlarmStru sysAlarmStru;
    HI_SWITCH_STATE_T hi_switch_state;
    work_mode workMode;
    uint16_t voltageSort[MAX_CEL_VOL_NUM];  /* 按有效值排序的单体电压 */
    uint16_t tempSort[MAX_TEMP_NUM];        /* 按有效值排序的单体电压 */

} _SystemDataStru;

typedef enum
{
    INT8_DATA,
    UINT8_DATA,
    INT16_DATA,
    UINT16_DATA,
    INT32_DATA,
    UINT32_DATA,
    U8_I8_DATA,
    FLOAT_DATA,
}_typeFormat_;

typedef enum
{
    TYPE_VALUE,
    TYPE_STR,
}_str_type_;

typedef struct
{
    char* key;
    _str_type_ f_str;
    _typeFormat_ type;
    void* p_value;
} St_ListIotKey;


void Update_BmsInfo_Thread(void *args);

_SystemDataStru *getBmsInf(void);
void BmsInfoInit(void);
void init_BmsInfoCellVolt(void);
void init_BmsInfoCellTempe(void);
void afe_CalcAdjustData(void);
void init_BmsInfoDefault(void);
St_ListIotKey* getmListKey(void);
size_t getSizeOfListKey(void);
void show_DispDateTime(void);
void updateBmsInfo_TaskEntry(void);

#endif

